home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Drawing / QDPatchBlock.cp < prev    next >
Text File  |  1997-06-28  |  2KB  |  82 lines

  1. // QDPatchBlock.cp
  2.  
  3. #ifndef QDPatchBlock_h
  4. #include "QDPatchBlock.h"
  5. #endif
  6. #ifndef GrafPortObject_h
  7. #include "GrafPortObject.h"
  8. #endif
  9.  
  10. const QDProcs& QDPatchBlock::MakeStandard()
  11.   {
  12.     static QDProcs standard;
  13.     SetStdProcs( &standard );
  14.     return standard;
  15.   }
  16.  
  17. const QDProcs& QDPatchBlock::Standard()
  18.   {
  19.     static const QDProcs& standard( MakeStandard() );
  20.     return standard;
  21.   }
  22.  
  23. QDPatchBlock::QDPatchBlock( GrafPortObject& thePort )
  24.   : QDProcs( Standard() ),
  25.      port( thePort )
  26.   {
  27.     Assert( port.grafProcs == 0 );
  28.     port.grafProcs = this;
  29.   }
  30.  
  31. QDPatchBlock::~QDPatchBlock()
  32.   {
  33.     Assert( port.grafProcs == this );
  34.     port.grafProcs = 0;
  35.   }
  36.  
  37. void QDPatchBlock::ActivateTextPatch()
  38.   {
  39.     Assert( textProc == Standard().textProc );
  40.     textProc = MyTextProc;
  41.   }
  42.  
  43. void QDPatchBlock::DeactivateTextPatch()
  44.   {
  45.     Assert( textProc == MyTextProc );
  46.     textProc = Standard().textProc;
  47.   }
  48.  
  49. pascal void QDPatchBlock::MyTextProc( int16 length,
  50.                                                   int8 *text,
  51.                                                   Point numerator,
  52.                                                   Point denominator )
  53.   {
  54.     A5 oldA5;
  55.     
  56.     GrafPort *thePort = **reinterpret_cast<GrafPort ***>( oldA5.Address() );
  57.     QDPatchBlock *self = static_cast<QDPatchBlock *>( thePort->grafProcs );
  58.     
  59.     self->a5.Restore();
  60.     
  61.     Assert( thePort != 0 );
  62.     Assert( thePort->grafProcs != 0 );
  63.     Assert( &self->port == thePort );
  64.  
  65.     self->portA5 = oldA5;
  66.     
  67.     self->DrawText( ConstData( text, length ),
  68.                          numerator,
  69.                          denominator );
  70.     
  71.     oldA5.Restore();
  72.   }
  73.  
  74. void QDPatchBlock::DrawText( ConstData text,
  75.                                       Point numerator,
  76.                                       Point denominator )
  77.   {
  78.     portA5.Restore();
  79.     StdText( text.Length(), text.Start(), numerator, denominator );
  80.     a5.Restore();
  81.   }
  82.